package com.twu.biblioteca.commands;

import com.twu.biblioteca.Biblioteca;

import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class ReturnCommand extends BibliotecaCommand {
    public static final String SUCCESS_MESSAGE = "Thank you for returning the book.";
    public static final String FAILURE_MESSAGE = "That is not a valid book to return.";

    public ReturnCommand(InputStream input, PrintStream output, Biblioteca biblioteca) {
        super("Return Book", input, output, biblioteca);
    }

    public boolean run() {
        if (!biblioteca.isLoggedIn()) {
            output.println(NOT_LOGGED_IN);
            return false;
        }

        Scanner scanner = new Scanner(input);

        output.print(BOOK_TITLE_PROMPT);
        output.println(biblioteca.returnBook(scanner.nextLine())
                ? SUCCESS_MESSAGE
                : FAILURE_MESSAGE);
        return false;
    }
}
